using UnityEngine;

public class DialogController : MonoBehaviour
{
	public CoinsController CoinsController;

	public GarageController GarageController;

	public UpgradeController UpgradeController;

	public BuyVehicleController BuyVehicleController;

	public GameObject dialog_canvas;

	public GameObject upgrade_speed_dialog;

	public GameObject upgrade_acceleration_dialog;

	public GameObject upgrade_brakes_dialog;

	public GameObject buy_vehicle_dialog;

	public GameObject not_enough_coins_dialog;

	public GameObject social_rewards;

	public GameObject social_rewarded;

	[HideInInspector]
	public bool dialog_showing;

	private void Start()
	{
		HideAllDialogs();
	}

	public void HideAllDialogs()
	{
		upgrade_speed_dialog.SetActive(value: false);
		upgrade_acceleration_dialog.SetActive(value: false);
		upgrade_brakes_dialog.SetActive(value: false);
		buy_vehicle_dialog.SetActive(value: false);
		not_enough_coins_dialog.SetActive(value: false);
		social_rewards.SetActive(value: false);
		social_rewarded.SetActive(value: false);
		dialog_canvas.SetActive(value: false);
		dialog_showing = false;
	}

	public void ShowNotEnoughCoinsDialog()
	{
		HideAllDialogs();
		dialog_canvas.SetActive(value: true);
		not_enough_coins_dialog.SetActive(value: true);
		dialog_showing = true;
	}

	public void ShowUpgradeSpeedDialog()
	{
		dialog_canvas.SetActive(value: true);
		upgrade_speed_dialog.SetActive(value: true);
		dialog_showing = true;
	}

	public void ShowUpgradeAccelerationDialog()
	{
		dialog_canvas.SetActive(value: true);
		upgrade_acceleration_dialog.SetActive(value: true);
		dialog_showing = true;
	}

	public void ShowUpgradeBrakesDialog()
	{
		dialog_canvas.SetActive(value: true);
		upgrade_brakes_dialog.SetActive(value: true);
		dialog_showing = true;
	}

	public void ShowBuyVehicleDialog()
	{
		dialog_canvas.SetActive(value: true);
		buy_vehicle_dialog.SetActive(value: true);
		dialog_showing = true;
	}

	public void ShowRewardsDialog()
	{
		dialog_canvas.SetActive(value: true);
		social_rewards.SetActive(value: true);
		dialog_showing = true;
	}

	public void ShowRewardedDialog()
	{
		dialog_canvas.SetActive(value: true);
		social_rewarded.SetActive(value: true);
		dialog_showing = true;
	}

	public void UpgradeSpeedClick()
	{
		if (BuyVehicleController.IsUnlocked(GarageController.active))
		{
			if (CoinsController.GetCurrentCoins() >= UpgradeController.GetSpeedPrice(GarageController.active))
			{
				ShowUpgradeSpeedDialog();
			}
			else
			{
				ShowNotEnoughCoinsDialog();
			}
		}
	}

	public void UpgradeAccelerationClick()
	{
		if (BuyVehicleController.IsUnlocked(GarageController.active))
		{
			if (CoinsController.GetCurrentCoins() >= UpgradeController.GetAccelerationPrice(GarageController.active))
			{
				ShowUpgradeAccelerationDialog();
			}
			else
			{
				ShowNotEnoughCoinsDialog();
			}
		}
	}

	public void UpgradeBrakesClick()
	{
		if (BuyVehicleController.IsUnlocked(GarageController.active))
		{
			if (CoinsController.GetCurrentCoins() >= UpgradeController.GetBrakesPrice(GarageController.active))
			{
				ShowUpgradeBrakesDialog();
			}
			else
			{
				ShowNotEnoughCoinsDialog();
			}
		}
	}

	public void BuyVehicleClick()
	{
		if (CoinsController.GetCurrentCoins() >= GarageController.prices[GarageController.active])
		{
			ShowBuyVehicleDialog();
		}
		else
		{
			ShowNotEnoughCoinsDialog();
		}
		UnityEngine.Debug.Log("Active vehicle: " + GarageController.active + "; Current coins: " + CoinsController.GetCurrentCoins() + "; Vehicle price: " + GarageController.prices[GarageController.active]);
	}

	public void BuySpeedClick()
	{
		CoinsController.SubstractCoins(UpgradeController.GetSpeedPrice(GarageController.active));
		UpgradeController.UpgradeSpeed(GarageController.active);
		GarageController.RefreshGUI();
		HideAllDialogs();
	}

	public void BuyAccelerationClick()
	{
		CoinsController.SubstractCoins(UpgradeController.GetAccelerationPrice(GarageController.active));
		UpgradeController.UpgradeAcceleration(GarageController.active);
		GarageController.RefreshGUI();
		HideAllDialogs();
	}

	public void BuyBrakesClick()
	{
		CoinsController.SubstractCoins(UpgradeController.GetBrakesPrice(GarageController.active));
		UpgradeController.UpgradeBrakes(GarageController.active);
		GarageController.RefreshGUI();
		HideAllDialogs();
	}

	public void BuyVehicleClickConfirm()
	{
		CoinsController.SubstractCoins(GarageController.prices[GarageController.active]);
		BuyVehicleController.BuyVehicle(GarageController.active);
		GarageController.RefreshGUI();
		HideAllDialogs();
	}
}
